package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVo;
import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService courseTeacherService;

    /**
     * 根据课程ID查询课程教师
     *
     * @param courseBaseId
     * @return
     */
    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryCourseTeacherById(@PathVariable("courseBaseId") Long courseBaseId) {
        Long companyId = UAASecurityUtil.getCompanyId();
        List<CourseTeacherDTO> dtos = courseTeacherService.queryCourseTeacherById(courseBaseId, companyId);
        return dtos;
    }

    /**
     * 新增或修改教师
     *
     * @param vo
     * @return
     */
    @PostMapping("courseTeacher")
    public CourseTeacherDTO saveOrUpdateCourseTeacher(@RequestBody CourseTeacherVo vo) {
        Long companyId = UAASecurityUtil.getCompanyId();
        CourseTeacherDTO dto = CourseTeacherConvert.INSTANCE.vo2dto(vo);
        CourseTeacherDTO result = courseTeacherService.saveOrUpdateCourseTeacher(dto, companyId);
        return result;
    }

    /**
     * 删除课程教师
     *
     * @param courseBaseId
     * @param courseTeacherId
     */
    @DeleteMapping("courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public void removeCourseTeacherById(@PathVariable("courseBaseId") Long courseBaseId, @PathVariable("courseTeacherId") Long courseTeacherId) {
        Long companyId = UAASecurityUtil.getCompanyId();
        courseTeacherService.removeCourseTeacherById(courseBaseId, courseTeacherId, companyId);
    }
}
